package com.bookstore.backend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bookstore.backend.model.ResultVO;
import com.bookstore.backend.model.entity.Order;
import com.bookstore.backend.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: world
 * @date: 2022/7/29 15:10
 * @description: 测试接口
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //根据orderId查询
    @RequestMapping(value = "/select",method = RequestMethod.GET)
    public ResultVO<?> orderSelect(Integer orderId){
        return ResultVO.success(orderService.orderSelect(orderId));
    }

    //分页
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    public ResultVO<Page<Order>> tableController(@RequestParam(value = "page",defaultValue = "1")Integer page, @RequestParam(value = "size",defaultValue = "5")Integer size){
        Page<Order> orderPage = new Page<Order>(page,size);
        Page<Order> result = orderService.page(orderPage);
        return ResultVO.success(result);
    }

    //添加
    @PostMapping("/insert")
    public ResultVO<?> orderinsert(@RequestBody Order order){
        return ResultVO.success(orderService.orderinsert(order));
    }

    //更新
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResultVO<?> updateNumByorderId(@RequestBody Order order){return ResultVO.success(orderService.updateNumByorderId(order));}

    //删除
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public  ResultVO<?> deleteNumByorderId(Integer orderId){
        return ResultVO.success(orderService.deleteNumByorderId(orderId));
    }
}
